package com.oj.friend.service.impl;

import com.oj.common.core.enums.ResultCode;
import com.oj.common.file.domain.OSSResult;
import com.oj.common.file.service.OssService;
import com.oj.common.security.exception.ServiceExpection;
import com.oj.friend.service.IFileService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description
 * @Author bin
 * @Date 2025/6/13
 */
@Slf4j
@Service
public class FileServiceImpl implements IFileService {

    @Resource
    private OssService ossService;

    @Override
    public OSSResult uploadFile(@RequestParam("file") MultipartFile file) {
        try {
            return ossService.uploadFile(file);
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new ServiceExpection(ResultCode.FAILED_FILE_UPLOAD);
        }
    }
}
